package com.pdemo.front.filter;

import java.io.IOException;

import javax.annotation.Priority;
import javax.ws.rs.Priorities;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerResponseContext;
import javax.ws.rs.container.ContainerResponseFilter;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.SecurityContext;
import javax.ws.rs.ext.Provider;

@Provider
@Priority(Priorities.USER)
public class ApplicationResponseFilter implements ContainerResponseFilter {
	
	@Context
	private SecurityContext m_securityContext;

	@Override
	public void filter(ContainerRequestContext requestContext,ContainerResponseContext responseContext) throws IOException {
		ApplicationPrincipal principal = (ApplicationPrincipal) m_securityContext.getUserPrincipal();
		if (principal != null){
			responseContext.getHeaders().add(Token.ROLES, principal.getRoles().toString());
		}
		
	}

}
